<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>唤醒本地应用</title>
  <style>
    .box {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }
    button {
      padding: 10px 20px;
      font-size: 18px;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <div class="box">
    <button onclick="wakeUpApp()">唤醒本地应用</button>
  </div>

  <script>
        function wakeUpApp() {
          const protocol = 'hiwi-app';
          const path = 'home';
          const token = 'abc123';
          const originUrl = encodeURIComponent(window.location.href); // 当前页面的 URL 作为来源

          const url = `${protocol}://${path}?token=${token}&origin=${originUrl}`;
          window.open(url);
        }
        let timer = null;
        timer = setInterval(() => {
          fetch('http://localhost:7777/status')
          .then(response => {
            if (!response.ok) {
              throw new Error('Network response was not ok ' + response.statusText);
            }
            return response.json();
          })
          .then(data => {
            console.log(data);
            timer && clearInterval(timer);
          })
          .catch(error => {
            console.error('There was a problem with the fetch operation:', error);
          });

        }, 1000);
  </script>
</body>
</html>
